/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('rmc', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model ListResourceRelationshipsRequest {
  maxResults?: int32(name='MaxResults', description='The maximum number of entries to return on each page.

Valid values: 1 to 100.

Default value: 20.', example='20'),
  nextToken?: string(name='NextToken', description='The token that is used to initiate the next request.

If the total number of entries returned for the current request exceeds the value of the `MaxResults` parameter, the entries are truncated. In this case, you can use the token to initiate another request and obtain the remaining entries.', example='eyJzZWFyY2hBZnRlcnMiOlsiMTAwMTU2Nzk4MTU1OSJd****'),
  sourceRegionId?: string(name='SourceRegionId', description='The region ID of the resource whose associated resources you want to query.', example='cn-shanghai'),
  sourceResourceId?: [ string ](name='SourceResourceId', description='The IDs of the resource whose associated resources you want to query.

You can specify a maximum of 10 resource IDs.'),
  sourceResourceType?: string(name='SourceResourceType', description='The type of the resource whose associated resources you want to query.', example='ACS::ECS::Instance'),
  targetResourceType?: [ string ](name='TargetResourceType', description='The types of the associated resources that you want to query.

You can specify a maximum of 10 resource types.'),
}

model ListResourceRelationshipsResponseBody = {
  maxResults?: int32(name='MaxResults', description='The maximum number of entries returned per page.', example='20'),
  nextToken?: string(name='NextToken', description='The token that is used to initiate the next request.', example='eyJzZWFyY2hBZnRlcnMiOlsiMTAwMTU2Nzk4MTU1OSJd****'),
  requestId?: string(name='RequestId', description='The ID of the request.', example='97765772-7E65-5D5E-BBB7-0CAF4D6260AA'),
  resourceRelationships?: [ 
    {
      accountId?: string(name='AccountId', description='The ID of the Alibaba Cloud account.', example='154035569884****'),
      sourceRegionId?: string(name='SourceRegionId', description='The region ID of the specified resource.', example='cn-shanghai'),
      sourceResourceId?: string(name='SourceResourceId', description='The ID of the specified resource.', example='i-uf6imlgyr1nudhud****'),
      sourceResourceType?: string(name='SourceResourceType', description='The type of the specified resource.', example='ACS::ECS::Instance'),
      targetRegionId?: string(name='TargetRegionId', description='The region ID of the associated resource.', example='cn-shanghai'),
      targetResourceId?: string(name='TargetResourceId', description='The ID of the associated resource.', example='vpc-uf6gvyids4utxhxe1****'),
      targetResourceType?: string(name='TargetResourceType', description='The type of the associated resource.', example='ACS::VPC::VPC'),
    }
  ](name='ResourceRelationships', description='The information of the associated resources.'),
}

model ListResourceRelationshipsResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: ListResourceRelationshipsResponseBody(name='body'),
}

/**
  * This section provides the types of resources that can be queried. Two-way queries are supported. For example, you can query the disks (ACS::ECS::Disk) that are associated with a specific Elastic Compute Service (ECS) instance (ACS::ECS::Instance) or query the ECS instance that is associated with a specific disk.  
  * - For ECS instances, the following types of resources can be queried:    - ACS::ECS::Disk
  *   - ACS::EIP::EipAddress
  *   - ACS::VPC::VPC
  *   - ACS::ECS::KeyPair
  *   - ACS::ECS::SecurityGroup
  *   - ACS::ECS::NetworkInterface
  *   - ACS::ECS::Image
  * - For virtual private clouds (VPCs), which are indicated by ACS::VPC::VPC, the following types of resources can be queried:    - ACS::ECS::Instance
  *   - ACS::RDS::DBInstance
  *   - ACS::SLB::LoadBalancer
  *   - ACS::ALB::LoadBalancer
  *   - ACS::Elasticsearch::Instance
  *   - ACS::Redis::DBInstance
  *   - ACS::PolarDB::DBCluster
  *   - ACS::MongoDB::DBInstance
  *   - ACS::DRDS::PolarDBXInstance
  *   - ACS::EDAS::Cluster
  *   - ACS::ECI::ContainerGroup
  *   - ACS::ADB::DBCluster
  *   - ACS::DRDS::DBInstance
  *   - ACS::HBase::Cluster
  *   - ACS::EMR::Cluster
  * This topic provides an example on how to call the API operation to query the resources that are associated with the ECS instance `i-uf6imlgyr1nudhud****` in the China (Shanghai) region.
  * ## Prerequisites
  * Resource Meta Center (RMC) is enabled. For more information, see [Query resources that belong to different resource groups](~~310198~~).
  * ## QPS limits
  * You can call this API operation up to 20 times per second per account. Requests that exceed this limit will fail, and you may experience service interruptions. We recommend that you take note of this limit when you call this operation.
  *
  * @param request ListResourceRelationshipsRequest
  * @param runtime runtime options for this request RuntimeOptions
  * @return ListResourceRelationshipsResponse
 */
async function listResourceRelationshipsWithOptions(request: ListResourceRelationshipsRequest, runtime: Util.RuntimeOptions): ListResourceRelationshipsResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.maxResults)) {
    query['MaxResults'] = request.maxResults;
  }
  if (!Util.isUnset(request.nextToken)) {
    query['NextToken'] = request.nextToken;
  }
  if (!Util.isUnset(request.sourceRegionId)) {
    query['SourceRegionId'] = request.sourceRegionId;
  }
  if (!Util.isUnset(request.sourceResourceId)) {
    query['SourceResourceId'] = request.sourceResourceId;
  }
  if (!Util.isUnset(request.sourceResourceType)) {
    query['SourceResourceType'] = request.sourceResourceType;
  }
  if (!Util.isUnset(request.targetResourceType)) {
    query['TargetResourceType'] = request.targetResourceType;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'ListResourceRelationships',
    version = '2021-11-04',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
  * This section provides the types of resources that can be queried. Two-way queries are supported. For example, you can query the disks (ACS::ECS::Disk) that are associated with a specific Elastic Compute Service (ECS) instance (ACS::ECS::Instance) or query the ECS instance that is associated with a specific disk.  
  * - For ECS instances, the following types of resources can be queried:    - ACS::ECS::Disk
  *   - ACS::EIP::EipAddress
  *   - ACS::VPC::VPC
  *   - ACS::ECS::KeyPair
  *   - ACS::ECS::SecurityGroup
  *   - ACS::ECS::NetworkInterface
  *   - ACS::ECS::Image
  * - For virtual private clouds (VPCs), which are indicated by ACS::VPC::VPC, the following types of resources can be queried:    - ACS::ECS::Instance
  *   - ACS::RDS::DBInstance
  *   - ACS::SLB::LoadBalancer
  *   - ACS::ALB::LoadBalancer
  *   - ACS::Elasticsearch::Instance
  *   - ACS::Redis::DBInstance
  *   - ACS::PolarDB::DBCluster
  *   - ACS::MongoDB::DBInstance
  *   - ACS::DRDS::PolarDBXInstance
  *   - ACS::EDAS::Cluster
  *   - ACS::ECI::ContainerGroup
  *   - ACS::ADB::DBCluster
  *   - ACS::DRDS::DBInstance
  *   - ACS::HBase::Cluster
  *   - ACS::EMR::Cluster
  * This topic provides an example on how to call the API operation to query the resources that are associated with the ECS instance `i-uf6imlgyr1nudhud****` in the China (Shanghai) region.
  * ## Prerequisites
  * Resource Meta Center (RMC) is enabled. For more information, see [Query resources that belong to different resource groups](~~310198~~).
  * ## QPS limits
  * You can call this API operation up to 20 times per second per account. Requests that exceed this limit will fail, and you may experience service interruptions. We recommend that you take note of this limit when you call this operation.
  *
  * @param request ListResourceRelationshipsRequest
  * @return ListResourceRelationshipsResponse
 */
async function listResourceRelationships(request: ListResourceRelationshipsRequest): ListResourceRelationshipsResponse {
  var runtime = new Util.RuntimeOptions{};
  return listResourceRelationshipsWithOptions(request, runtime);
}

model SearchResourcesRequest {
  filter?: [ 
    {
      key?: string(name='Key', description='The key of the filter condition. Valid values:

*   ResourceType: resource type
*   RegionId: region ID
*   ResourceId: resource ID
*   ResourceGroupId: resource group ID
*   ResourceName: resource name', example='RegionId'),
      matchType?: string(name='MatchType', description='The matching method. Set the value to Equals. This value indicates that resources that match the filter conditions are queried.', example='Equals'),
      value?: [ string ](name='Value', description='The values of the filter condition.'),
    }
  ](name='Filter', description='The filter conditions.'),
  maxResults?: int32(name='MaxResults', description='The maximum number of entries to return on each page.

Valid values: 1 to 100.

Default value: 20.', example='5'),
  nextToken?: string(name='NextToken', description='The token that is used to initiate the next request.

If the total number of entries returned for the current request exceeds the value of the `MaxResults` parameter, the entries are truncated. In this case, you can use the token to initiate another request and obtain the remaining entries.', example='eyJzZWFyY2hBZnRlcnMiOlsiMTAwMTU2Nzk4MTU1OSJd****'),
  resourceGroupId?: string(name='ResourceGroupId', description='The ID of the resource group.', example='rg-acfmzawhxxc****'),
  sortCriterion?: {
    key?: string(name='Key', description='The attribute based on which the entries are sorted.

The value `CreateTime` indicates the creation time of resources.', example='CreateTime'),
    order?: string(name='Order', description='The order in which the entries are sorted. Valid values:

*   ASC: The entries are sorted in ascending order. This value is the default value.
*   DESC: The entries are sorted in descending order.', example='ASC'),
  }(name='SortCriterion', description='The method that is used to sort the entries.'),
}

model SearchResourcesResponseBody = {
  filters?: [ 
    {
      key?: string(name='Key', description='The key of the filter condition.', example='RegionId'),
      matchType?: string(name='MatchType', description='The matching method.', example='Equals'),
      values?: [ string ](name='Values', description='The values of the filter condition.'),
    }
  ](name='Filters', description='The filter conditions.'),
  maxResults?: int32(name='MaxResults', description='The maximum number of entries returned per page.', example='5'),
  nextToken?: string(name='NextToken', description='The token that is used to initiate the next request.', example='eyJzZWFyY2hBZnRlcnMiOlsiMTAwMTU2Nzk4MTU1OSJd****'),
  requestId?: string(name='RequestId', description='The ID of the request.', example='14B1E620-E24F-5A0E-B130-AB1488F4F9F1'),
  resources?: [ 
    {
      accountId?: string(name='AccountId', description='The ID of the Alibaba Cloud account.', example='151266687691****'),
      createTime?: string(name='CreateTime', description='The time when the resource was created.

>  Whether this parameter is returned is determined by the Alibaba Cloud service to which the resource belongs.', example='2021-06-30T09:20:08Z'),
      ipAddresses?: [ string ](name='IpAddresses', description='The IP addresses.

>  Whether this parameter is returned is determined by the Alibaba Cloud service to which the resource belongs.'),
      regionId?: string(name='RegionId', description='The region ID.', example='cn-hangzhou'),
      resourceGroupId?: string(name='ResourceGroupId', description='The ID of the resource group.', example='rg-acfmzawhxxc****'),
      resourceId?: string(name='ResourceId', description='The ID of the resource.', example='vtb-bp11lbh452fr8940s****'),
      resourceName?: string(name='ResourceName', description='The name of the resource.', example='group1'),
      resourceType?: string(name='ResourceType', description='The type of the resource.', example='ACS::VPC::RouteTable'),
      tags?: [ 
        {
          key?: string(name='Key', description='The tag key.', example='k1'),
          value?: string(name='Value', description='The tag value.', example='v1'),
        }
      ](name='Tags', description='The tags.'),
      zoneId?: string(name='ZoneId', description='The zone ID.

>  Whether this parameter is returned is determined by the Alibaba Cloud service to which the resource belongs.', example='cn-hangzhou-k'),
    }
  ](name='Resources', description='The information of the resources.'),
}

model SearchResourcesResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: SearchResourcesResponseBody(name='body'),
}

/**
  * For more information about resource types that support RMC, see [Resource types that support RMC](https://www.alibabacloud.com/help/en/resource-management/latest/resource-types-that-support-rmc).  
  * This topic provides an example on how to call the API operation to query the resources that can be accessed within the current account in the China (Hangzhou) region.
  * ## Prerequisites
  * Resource Meta Center (RMC) is enabled. For more information, see [Query resources that belong to different resource groups](~~310198~~).
  * ## QPS limits
  * You can call this API operation up to 20 times per second per account. Requests that exceed this limit will fail, and you may experience service interruptions. We recommend that you take note of this limit when you call this operation.
  *
  * @param request SearchResourcesRequest
  * @param runtime runtime options for this request RuntimeOptions
  * @return SearchResourcesResponse
 */
async function searchResourcesWithOptions(request: SearchResourcesRequest, runtime: Util.RuntimeOptions): SearchResourcesResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.filter)) {
    query['Filter'] = request.filter;
  }
  if (!Util.isUnset(request.maxResults)) {
    query['MaxResults'] = request.maxResults;
  }
  if (!Util.isUnset(request.nextToken)) {
    query['NextToken'] = request.nextToken;
  }
  if (!Util.isUnset(request.resourceGroupId)) {
    query['ResourceGroupId'] = request.resourceGroupId;
  }
  if (!Util.isUnset(request.sortCriterion)) {
    query['SortCriterion'] = request.sortCriterion;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'SearchResources',
    version = '2021-11-04',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
  * For more information about resource types that support RMC, see [Resource types that support RMC](https://www.alibabacloud.com/help/en/resource-management/latest/resource-types-that-support-rmc).  
  * This topic provides an example on how to call the API operation to query the resources that can be accessed within the current account in the China (Hangzhou) region.
  * ## Prerequisites
  * Resource Meta Center (RMC) is enabled. For more information, see [Query resources that belong to different resource groups](~~310198~~).
  * ## QPS limits
  * You can call this API operation up to 20 times per second per account. Requests that exceed this limit will fail, and you may experience service interruptions. We recommend that you take note of this limit when you call this operation.
  *
  * @param request SearchResourcesRequest
  * @return SearchResourcesResponse
 */
async function searchResources(request: SearchResourcesRequest): SearchResourcesResponse {
  var runtime = new Util.RuntimeOptions{};
  return searchResourcesWithOptions(request, runtime);
}

